package com.uroad.lib.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.widget.TextView;

import com.uroad.lib.R;
import com.uroad.lib.widget.RoundProgressBar;

public class RoundProgressDialog extends Dialog {
    private int progress = 0;
    private RoundProgressBar roundProgressBar;
    private TextView tv_state;
    private Context context;
    public RoundProgressDialog(Context context) {
        super(context);
    }

    public RoundProgressDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }


    protected RoundProgressDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_progress);
        roundProgressBar = (RoundProgressBar) findViewById(R.id.roundProgressBar);
        tv_state = (TextView) findViewById(R.id.tv_state);
    }

    public void setMessage(final String message){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if(message.contains("/")){
                    String[] split = message.split("/");
                    double i = Double.parseDouble(split[0]);
                    double i1 = Double.parseDouble(split[1]);
                    int i2 = (int) ((i / i1) * 100);
                    roundProgressBar.setProgress(i2);
                }else{
                    roundProgressBar.setProgress(99);
                }
                tv_state.setText("更新中"+message);
            }
        },1000);
    }
}
